package com.cart.protocol.analyze;

import android.util.Log;

import com.cart.protocol.ProtocolDefine;


/*
    ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ 
       Author   :  lixiaodaoaaa
       Date     :  2020-01-16
       Time     :  10:37
    ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
    关于 门指令回复的解析
 */
public class DoorRespAnalyze extends RespAnalyze {

    private static final String TAG = "DOOR";

    public DoorRespAnalyze(String rawDeviceInfo) {
        super(rawDeviceInfo);
    }


    protected DoorRespAnalyze analyze() {
        //10 05 01 ff 01
        //20 05 01 cc 00
        //20 05 01 aa 00
        //10 05 01 ff 01
        //20 05 01 cc 00
        //对门的操作解析
        String doorOperator = rawDeviceInfo.substring(length - 4, length - 2);
        switch (doorOperator.toUpperCase()) {
            case ProtocolDefine.OperateCommand.CLOSE:
                Log.i(TAG, "电机门关闭");
                report = "电机门关闭";
                break;
            case ProtocolDefine.OperateCommand.OPEN:
                Log.i(TAG, "电机门开启");
                report = "电机门开启";
                break;
            case ProtocolDefine.OperateCommand.READ:
                readDoorStatus();
                break;
            case ProtocolDefine.OperateCommand.STOP:
                Log.i(TAG, "电机门紧急停止");
                report = "电机门紧急停止";
                break;
            default:
                break;
        }
        return this;
    }

    private void readDoorStatus() {
        String doorStatus = rawDeviceInfo.substring(length - 2, length);
        switch (doorStatus.toUpperCase()) {
            case ProtocolDefine.DoorStatus.DOOR_CLOSE:
                System.out.println("电机门关闭");
                report = "电机门关闭";
                break;
            case ProtocolDefine.DoorStatus.DOOR_OPEN_HALF:
                System.out.println("电机门半开半闭状态");
                report = "电机门半开半闭状态";
                break;
            case ProtocolDefine.DoorStatus.DOOR_OPEN_BIGGEST:
                System.out.println("电机门处于开启最大位置");
                report = "电机门处于开启最大位置";
                break;
            default:
                break;
        }
    }
}
